package cn.flying.cloud.system.resource.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;

import cn.flying.cloud.system.resource.entity.SysResInfo;

/**
 * <p>
 * 资源信息表 Mapper 接口
 * </p>
 *
 * @author admin
 * @since 2024-04-02 13:07:17
 */
@Mapper
public interface SysResInfoMapper extends BaseMapper<SysResInfo> {

    /**
     * 根据用户Id查询拥有的权限菜单
     *
     * @param userId
     * @return
     */
    @Select({"select " +
            " distinct t3.* " +
            "from " +
            " sys_user_role t1, " +
            " sys_role_res t2, " +
            " sys_res_info t3  " +
            "where " +
            " t1.role_id = t2.role_id  " +
            " and t2.res_id = t3.res_id  " +
            " and t1.tenant_id = t3.tenant_id  " +
            " and t2.tenant_id = t3.tenant_id  " +
            " and t1.deleted = '0'  " +
            " and t2.deleted = '0'  " +
            " and t3.deleted = '0'  " +
            " and t3.type != 'B'  " +
            " and t3.status = 'Y'  " +
            " and t1.user_id = #{userId}" +
            " and t1.tenant_id = #{tenantId}"})
    List<SysResInfo> getMenuInfosByUserId(@Param("userId") String userId, @Param("tenantId") String tenantId);

    /**
     * 根据用户Id查询拥有的权限资源
     *
     * @param userId
     * @return
     */
    @Select({"select " +
            " distinct t3.* " +
            "from " +
            " sys_user_role t1, " +
            " sys_role_res t2, " +
            " sys_res_info t3  " +
            "where " +
            " t1.role_id = t2.role_id  " +
            " and t2.res_id = t3.res_id  " +
            " and t1.tenant_id = t3.tenant_id  " +
            " and t2.tenant_id = t3.tenant_id  " +
            " and t1.deleted = '0'  " +
            " and t2.deleted = '0'  " +
            " and t3.deleted = '0'  " +
            " and t3.status = 'Y'  " +
            " and t1.user_id = #{userId}" +
            " and t1.tenant_id = #{tenantId}"})
    List<SysResInfo> getResInfosByUserId(@Param("userId") String userId, @Param("tenantId") String tenantId);
}
